"""
def power(x, n):
    s = 1
    while n > 0:
        n = n - 1
        s = s * x
    return s

print(power(5,2))
"""


def power(x, n=2):
    s = 1
    while n > 0:
        n = n - 1
        s = s * x
    return s


print(power(5, 2))
print(power(5))


def add_end(L=[]):
    L.append('END')
    return L


print(add_end())
print(add_end())


# 定义默认参数要牢记一点：默认参数必须指向不变对象！

def add_end(L=None):
    if L is None:
        L = []
    L.append('END')
    return L


print(add_end())
print(add_end())

"""
def calc(numbers):
    sum = 0
    for n in numbers:
        sum = sum + n * n
    return sum


print(calc([1, 2, 3, 4]))
"""


# 函数的参数改为可变参数
def calc_sum(*numbers):
    sum = 0
    for n in numbers:
        sum = sum + n * n
    return sum


print(calc_sum(1, 2, 3, 4, 5))

# 将list 转换为可变参数
nums = [1, 2, 3, 4, 5]
print(calc_sum(*nums))

def person(name, age, **kw):
    print('name:', name, "age:", age, 'other:', kw)


person('Michael', 30)

person('Michael', 30, city='Beijing')
person('Michael', 30, city='Beijing', job='Engineer', gender='M')

extra = {'city': 'Beijing', 'job': 'Engineer'}
person('Jack', 24, city=extra['city'], job=extra['job'])
person('Jack Tom', **extra)
